import requests
import json
import sys

# 添加项目根目录到Python路径
sys.path.append('c:\\Users\\Administrator\\Desktop\\1\\aichat')

# 导入配置管理器
from backend.common.config import config_manager

# 直接打印config_manager.api.version的值
print(f"config_manager.api.version = {config_manager.api.version}")

# 从settings导入API_VERSION
from backend.settings import API_VERSION
print(f"settings.API_VERSION = {API_VERSION}")

# 测试几个明确的路径组合
test_paths = [
    f'http://localhost:8001/{config_manager.api.version}/chat',
    f'http://localhost:8001/{config_manager.api.version}/chat/',
    f'http://localhost:8001/api/{config_manager.api.version}/chat',
    f'http://localhost:8001/api/{config_manager.api.version}/chat/',
    f'http://localhost:8001/{API_VERSION}/chat',
    f'http://localhost:8001/{API_VERSION}/chat/',
    f'http://localhost:8001/api/{API_VERSION}/chat',
    f'http://localhost:8001/api/{API_VERSION}/chat/',
    'http://localhost:8001/chat',
    'http://localhost:8001/chat/',
    'http://localhost:8001/api/chat',
    'http://localhost:8001/api/chat/',
    'http://localhost:8001/v1/chat',
    'http://localhost:8001/v1/chat/',
    'http://localhost:8001/api/v1/chat',
    'http://localhost:8001/api/v1/chat/'
]

# 请求数据
data = {
    'session_id': 'test_chat',
    'message': 'hello',
    'use_rag': True,
    'use_tools': True,
    'stream': True
}

headers = {'Content-Type': 'application/json'}

# 测试每个路径
for path in test_paths:
    print(f"\n测试路径: {path}")
    try:
        response = requests.post(path, headers=headers, data=json.dumps(data), timeout=5)
        print(f"状态码: {response.status_code}")
        print(f"响应内容: {response.text}")
        
        # 如果找到有效路径，提前结束测试
        if response.status_code == 200:
            print("\n找到有效路径！")
            break
    except Exception as e:
        print(f"请求失败: {e}")
